package com.wzj.yygh.order.controller.api;

import com.wzj.yygh.common.result.R;
import com.wzj.yygh.common.result.ResultCode;
import com.wzj.yygh.order.service.WeixinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "微信支付接口")
@RestController
@RequestMapping("/api/order/wxpay")
public class ApiWXPayController {

    @Autowired
    private WeixinService weixinService;

//    @Autowired
//    private PaymentService paymentService;

    //生成微信支付二维码
    @ApiOperation("生成微信支付二维码")
    @GetMapping("createNative/{orderId}")
    public R createNative(@PathVariable Long orderId) {
        boolean flag = weixinService.createNative(orderId);
        return R.ok().data("codeUrl",flag);
    }

    @ApiOperation("查询支付状态")
    @GetMapping("queryPayStatus/{orderId}")
    public R queryPayStatus(@PathVariable Long orderId) {
        //调用微信接口实现支付状态查询
        boolean success = weixinService.queryPayStatus(orderId);
        //判断
        if(success) { //支付成功
            return R.ok().message("支付成功");
        }
        return R.ok().message("支付中").code(ResultCode.PAYING);
    }
}
